package core2.ch04database;

import java.sql.*;

public class AccessDB {
	String sDBDriver;

	String sConnStr;

	Connection conn;

	ResultSet rs;
	

	public AccessDB() {
		sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
		sConnStr = "jdbc:odbc:shnxn";
		conn = null;
		rs = null;
		try {
			Class.forName(sDBDriver);
		} catch (ClassNotFoundException classnotfoundexception) {
			System.err.println("DB(): " + classnotfoundexception.getMessage());
		}
	}

	public void executeInsert(String s) {
		try {
			conn = DriverManager.getConnection(sConnStr);
			Statement statement = conn.createStatement(1004, 1008);
			int i = statement.executeUpdate(s);
		} catch (SQLException sqlexception) {
			System.err
					.println("DB.executeUpdate:" + sqlexception.getMessage());
		}
	}

	public ResultSet executeQuery(String s) {
		rs = null;
		try {
			conn = DriverManager.getConnection(sConnStr);
			Statement statement = conn.createStatement(1004, 1008);
			rs = statement.executeQuery(s);
		} catch (SQLException sqlexception) {
			System.err.println("DB.executeQuery: " + sqlexception.getMessage());
		}
		return rs;
	}
	public int executeUpdate(String s) {
		int i = 0;
		try {
			conn = DriverManager.getConnection(sConnStr);
			Statement statement = conn.createStatement(1004, 1008);
			i = statement.executeUpdate(s);
		} catch (SQLException sqlexception) {
			System.err.println("DB.executeUpate: "
					+ sqlexception.getMessage());
		}
		return i;
	}

	public void executeDelete(String s) {
		try {
			conn = DriverManager.getConnection(sConnStr);
			Statement statement = conn.createStatement(1004, 1008);
			statement.executeUpdate(s);
		} catch (SQLException sqlexception) {
			System.err.println("DB.executeDelete: "
					+ sqlexception.getMessage());
		}
	}
	public void Close() {
		try {
			if (rs != null)
				rs.close();
			if (conn != null)
				conn.close();
		} catch (SQLException sqlexception) {
			System.err.println("DB.Close: "
					+ sqlexception.getMessage());
		}
	}
}